﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using Zj.DDDSample.Domain.Interface;

namespace Zj.DDDSample.Repositories.EntityFrameworkCore
{
    /// <summary>
    /// multi dbcontext transaction,support distributed transaction implement
    /// </summary>
    public class UnitWork : IUnitWork
    {
        private TransactionScope trans = null;
        public UnitWork()
        {
            trans = new TransactionScope();
        }

        public void Commit()
        {
            if (trans != null)
            {
                trans.Complete();//have to use scope.Complete to let date update to database
            }
        }

        public void Dispose()
        {
            if (trans != null)
            {
                trans.Dispose();
            }
        }
    }
}
